//
//  NavigationController.m
//  ViewControllerTransition
//
//  Created by chavez on 2017/6/28.
//  Copyright © 2017年 chavez. All rights reserved.
//

#import "NavigationController.h"
#import "MJ_UserMessage.h"
#import "MessageViewController.h"
#import "UIImage+Color.h"
#import "UIColor+Extend.h"
#import "UIView+Badge.h"
@interface NavigationController ()<UINavigationControllerDelegate>

@property (strong, nonatomic)MJ_UserMessage *headIconSingle;

@end

@implementation NavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    _headIconSingle = [MJ_UserMessage sharedInstance];
    UIBarButtonItem *back = [[UIBarButtonItem alloc] init];
    back.title = @"";
    self.navigationItem.backBarButtonItem = back;
    self.navigationBar.tintColor = [UIColor whiteColor];
    UIImage *backButtonImage = [[UIImage imageNamed:@"Nav_返回"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSForegroundColorAttributeName:RGB(51, 51, 51, 1)}];
    self.navigationBar.backIndicatorImage = backButtonImage;
    self.navigationBar.backIndicatorTransitionMaskImage = backButtonImage;
    self.interactivePopGestureRecognizer.enabled = NO;
    self.navigationBar.translucent = NO;
    self.delegate = self;
    self.navigationBar.shadowImage = [UIImage createImageWithColor:[UIColor colorWithHexString:@"#e0e0e0"]];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
    
    if (self.childViewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
        [_headIconSingle.userHeadButton removeFromSuperview];
        [_headIconSingle.messageBarButton removeFromSuperview];
        [_headIconSingle.topView removeFromSuperview];
        [_headIconSingle.midView removeFromSuperview];
        [_headIconSingle.footView  removeFromSuperview];
        MMDrawerController *vc = [MJ_UserMessage sharedInstance].currentDrawerController;
        vc.openDrawerGestureModeMask = MMOpenDrawerGestureModeNone;
        vc.closeDrawerGestureModeMask = MMCloseDrawerGestureModeNone;
    }
    [super pushViewController:viewController animated:animated];

}

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count == 1) {
        [self.navigationBar addSubview:_headIconSingle.userHeadButton];
        [self.navigationBar addSubview:_headIconSingle.messageBarButton];
        [self.navigationBar addSubview:_headIconSingle.topView];
        [self.navigationBar addSubview:_headIconSingle.midView];
        [self.navigationBar addSubview:_headIconSingle.footView];
        
        MMDrawerController *vc = [MJ_UserMessage sharedInstance].currentDrawerController;
        vc.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
        vc.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
    }
}

@end
